package com.worthtech.billportal.dao.hibernate;

import java.util.List;

import com.worthtech.billportal.bean.BillShop;
import com.worthtech.billportal.bean.BillShopbank;
import com.worthtech.billportal.bean.BillTradecode;
import com.worthtech.billportal.dao.ShopDAO;
import com.worthtech.billportal.exception.SCException;
import com.worthtech.billportal.util.AbstractManager;

public class ShopHibernateDAO extends AbstractManager implements ShopDAO {
	public List getListByHQL(String tableName, int startPage, int perNo,
			String orderby) {
		String hql = "from " + tableName + " " + orderby;
		System.out.println("hql2=" + hql);
		if (perNo == 0) {
			return this.getSession().createQuery(hql).list();
		}
		return this.getSession().createQuery(hql).setFirstResult(startPage)
				.setMaxResults(perNo).list();
	}

	public String getCount(String tableName, String condition) {
		String hql = "select count(*) from " + tableName + " " + condition;
		System.out.println("hql1=" + hql);
		String tmp = this.getSession().createQuery(hql).list().get(0)
				.toString();
		System.out.println("count=" + tmp);
		return tmp;
	}

	public void addShop(BillShop shop) throws SCException {
		this.getHibernateTemplate().save(shop);
	}

	public void updateShop(BillShop shop) throws SCException {
		this.getHibernateTemplate().update(shop);
	}

	public void delShop(BillShop shop) throws SCException {
		this.getHibernateTemplate().delete(shop);
	}

	public void addBank(BillShopbank shop) throws SCException {
		this.getHibernateTemplate().save(shop);
	}

	public void updateBank(BillShopbank shop) throws SCException {
		this.getHibernateTemplate().update(shop);
	}

	public void delBank(BillShopbank shop) throws SCException {
		this.getHibernateTemplate().delete(shop);
	}
	public void addTrade(BillTradecode shop) throws SCException {
		this.getHibernateTemplate().save(shop);
	}

	public void updateTrade(BillTradecode shop) throws SCException {
		this.getHibernateTemplate().update(shop);
	}

	public void delTrade(BillTradecode shop) throws SCException {
		this.getHibernateTemplate().delete(shop);
	}
	public void delTable(String tablename,String sql) throws SCException{
		this.getSession().createQuery("delete "+tablename+" "+sql).executeUpdate();
	}
}
